import axios from 'axios'
import { message } from 'ant-design-vue';

export function post_with_sk(url, data, args) {
    var url_real = 'http://localhost:5027/api'+url;
    axios.post(url_real, data).then(rsp => {
        if (rsp.relogin) {
            message.warn('This is a normal message');
            location.href = '/User/Login';
            return;
        }

        if (rsp.error_msg && !args.noerror) {
            message.warn('This is a normal message');
        }
    })
}

export function post_no_sk(url, data, args) {
    var url_real = 'http://localhost:5027/api'+url;
    axios.post(url_real, data).then(rsp => {
        if (rsp.relogin) {
            message.warn('This is a normal message');
            location.href = '/User/Login';
            return;
        }

        if (rsp.error_msg && !args.noerror) {
            message.warn('This is a normal message');
        }
    })
}

export function get_with_sk(url, data, args) {
    var url_real = 'http://localhost:5027/api'+url;
    axios.get(url_real, data).then(rsp => {
        if (rsp.relogin) {
            message.warn('This is a normal message');
            location.href = '/User/Login';
            return;
        }

        if (rsp.error_msg && !args.noerror) {
            message.warn('This is a normal message');
        }
    })
}

export function get_no_sk(url, data, args) {
    var url_real = 'http://localhost:5027/api'+url;
    axios.get(url_real, data).then(rsp => {
        if (rsp.relogin) {
            message.warn('This is a normal message');
            location.href = '/User/Login';
            return;
        }

        if (rsp.error_msg && !args.noerror) {
            message.warn('This is a normal message');
        }
    })
}